
package application;

import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
import javafx.scene.text.Text;
import jeopardy.common.protocol.game.*;

public class PreGameScreenController implements Initializable , ControlledScreen {

	// Variables for reading input from the form
	@FXML
	private Text preGameMessage;
    
    @FXML
    private ListView<String> gameList;

  /*  
    @FXML
    TableView<ObservableIssue> table;
  */
 
    UserSession sessionX = UserSession.getInstance();
    PreGameScreenSession sessionG = PreGameScreenSession.getInstance();

    String userName;
    char[] passWord;
    

	ScreensController myController;
	
	
    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
    	       
        
        /********
        // Show a list of available games
    	// change next line to DB load
        List<String> values = Arrays.asList("jeopardy");
        gameList.setItems(FXCollections.observableList(values));
        *********/
        
    	/******* HAS BEEN MOVED TO LoginScreenController
        // Invoke PreGameScreenLogic to start the data retrieval from server
        try {
			PreGameScreenLogic.main();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	 ************/
    	
        /********
         * Show a list of available games
         * 
    	 ********/
        System.out.println("Printing list of available games");
        sessionG.printList();

        gameList.setItems(FXCollections.observableList(sessionG.myAvailableGames));

        // Show instructions to the users to select a game or start a new game
        preGameMessage.setText("    From the list above please select a game and push"
        		+ "\"Join Game\" Button \n    or push the button \"Create Game\" to create "
        		+ "a new game\n\n");
		
    }
    
    public void setScreenParent(ScreensController screenParent){
        myController = screenParent;
    }
    
    /*
     * Call this method when when the "Join Game" button is pushed
     * 
     */
    @FXML
    private void processJoinGameRequest(ActionEvent event){
    	/* TODO - get the user selected game id - Testing ID supported is "jeopardy"
    	 * 
    	*/
    	
       // myController.setScreen(ScreensFramework.WelcomeScreenID);
       preGameMessage.setText("    Adding you to the requested game");
       // System.out.println("Game join request received");
       // GameManagerRequest newRequest = new GameManagerRequest();
       System.out.println("User name provided is: "+ sessionX.getUserName());
       // System.out.println("Password provided is: "+ sessionX.getPassword().toString());
       System.out.println("Password provided is: "+ new String(sessionX.getPassword()));

    }
    /*
     * Call this method when when the "Create Game" button is pushed
     * 
     */
    @FXML
    private void processCreateNewGameRequest(ActionEvent event){
       // myController.setScreen(ScreensFramework.RegistrationScreenID);
       preGameMessage.setText("    Creating a new game for you");
       // System.out.println("Game creation request received");

    }
}
